<template>
	<view class="page">
		<!-- 地址列表 -->
		<view class="address-list" v-if="dataList.length!=0">
			<view class="list" v-for="(item,index) in dataList" :key="index">
				<view class="name-phone">
					<view class="name">
						<text class="one-omit">{{item.name}}</text>
					</view>
					<view class="phone">
						<text>{{item.phone}}</text>
						<text class="tag" v-if="item.type==1">默认</text>
					</view>
				</view>
				<view class="address-edit">
					<view class="address">
						<text>{{item.province}}{{item.city}}{{item.area}}{{item.address}}</text>
					</view>
					<view class="edit" @click.stop="getDel(item.code)">
						<text class="cuIcon cuIcon-delete"></text>
					</view>
					<view class="edit" @click.stop="onAddressEdit('/pages/AddressEdit/AddressEdit?type=1&&code='+JSON.stringify(item))">
						
						<text class="iconfont icon-edit1"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="empty-box" v-if="dataList.length==0">
			<image src="../../static/ic_nodata.png" mode=""></image>
			<view class="">暂无数据</view>
		</view>
		<!-- 添加地址 -->
		<view class="add-address">
			<view class="btn" @click="onAddressEdit('/pages/AddressEdit/AddressEdit?type=2')">
				<text>新建收货地址</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				dataList:[]
			};
		},
		onShow() {
			this.page=1
			this.dataList=[]
			this.getList()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods:{
			/**
			 * 编辑地址点击
			 */
			onAddressEdit(type){
				uni.navigateTo({
					url: type,
				})
			},
			getList(){
				let that = this
				that.tui.request("api.auth.address/get", "POST", {page:that.page}, false, false, false).then((res) => {
					if(res.code==1){
						that.dataList = that.dataList.concat(res.data.list)
					}
				}).catch((res) => {
					
				})
			},
			getDel(e){
				let that = this
				that.tui.request("api.auth.address/remove", "POST", {code:e}, false, false, false).then((res) => {
					that.tui.toast(res.info)
					if(res.code==1){
						setTimeout(function(){
							that.page=1
							that.dataList=[]
							that.getList()
						},1000)
						
					}
				}).catch((res) => {
					
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'AddressList.scss';
</style>
